package study.config;

import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;

/**
 *
 *
 */
@Configuration
@Slf4j
public class FeignConfig {

    /**
     * 打印feign全部的日志
     */
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
//        return Logger.Level.NONE;
    }

    /**
     * 请求头部设置
     *
     * @return RequestInterceptor
     */
    @Bean
    public RequestInterceptor headerInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                Long timestamp = System.currentTimeMillis();
                template.header("content-type", MediaType.APPLICATION_JSON_UTF8_VALUE);
                template.header("timestamp", String.valueOf(timestamp));
            }
        };
    }

}
